package com.cxf.windex.rest;

import com.cxf.windex.base.msg.ObjectRestResponse;
import com.cxf.windex.base.rest.BaseRestController;
import com.cxf.windex.biz.PayInfoBiz;
import com.cxf.windex.entity.JsTech;
import com.cxf.windex.entity.PayInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;

/**
 * 微信支付接口
 *
 * @author chenxf
 * @version 1.0
 * @date 2018-12-10 09:43
 **/
@Api(tags = {"通用 - 微信支付接口"})
@Controller
@RequestMapping("/user/wxpay")
public class WxPayController extends BaseRestController<PayInfoBiz, PayInfo> {
    @ApiOperation(value = "认证费", notes = "获取认证费")
    @RequestMapping(value = "/certFee", method = RequestMethod.GET)
    @ResponseBody
    public ObjectRestResponse certFee(){
        return new ObjectRestResponse("查询成功").rel(true).result(baseBiz.certFee());
    }

    @ApiOperation(value = "获取订单信息", notes = "获取订单信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "openid", value = "openid", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "fee", value = "支付费用", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "type", value = "支付类型 s_wx_recharge充值 s_wx_cert 认证 s_wx_orders 订单支付", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "bindId", value = "绑定订单",  paramType = "query", dataType = "String"),
    })
    @RequestMapping(value = "/orderInfo", method = RequestMethod.GET)
    @ResponseBody
    public ObjectRestResponse orderInfo( String openid, String fee, String type, String bindId){
        return new ObjectRestResponse("查询成功").rel(true).result(baseBiz.getOrderInfo(openid,fee,type.trim(),bindId,getClientIp()));
    }

    @ApiOperation(value = "支付失败", notes = "支付失败")
    @RequestMapping(value = "/payfail/{payId}", method = RequestMethod.POST)
    @ResponseBody
    public ObjectRestResponse payfail(@PathVariable String payId) {
       baseBiz.payFail(payId);
        return new ObjectRestResponse().rel(true).msg("保存成功");
    }

    @ApiOperation(value = "支付结果", notes = "支付结果")
    @RequestMapping(value = "/notify", method = {RequestMethod.GET, RequestMethod.POST})
    @ResponseBody
    public String notify(HttpServletRequest request) {
        return baseBiz.payResult(request);
    }
}
